|
|
|
|
|
|
|
While you are in break mode, printing out variable values in the Immediate window is common practice. However, Visual Basic includes two special features for keeping track of variables during program execution. One of them is simple; just hover the mouse pointer over the variable name, and the value appears in a ToolTip. The other, more advanced method is to use the Watches window, as shown in Figure 10.4. |
|
|
|
|
|
|
|
|
Figure 10.4
In the Watches window, you can watch and change variable values. |
|
|
|
|
|
|
|
|
To monitor a variable in the Watches window, simply right-click the variable, and choose Add Watch from the context menu. Try it now: Start a new Standard EXE project, and enter the following code in the Form_Load event: |
|
|
|
|
|
|
|
|
Private Sub Form_Load()
Dim strArray(1 To 10) As String
strArray(1) = "One"
strArray(2) = "Two"
strArray(3) = "Three"
End Sub |
|
|
|
|
|
|
|
|
While you are still in design mode, right-click strArray and select Add Watch. The Add Watch dialog box appears, as shown in Figure 10.5. Click the OK button, and the Watches window includes an entry for strArray. Notice that the Value column displays <Out of context>, because the program has not started yet, and the array doesn't exist. Press F8 once to start the program, and make sure that the Watches window is visible. If it is not, choose View, WatchWindow. Press F8 several times, each time stopping to inspect the Watches window. The values for each element of strArray should be displayed in the window. You can even double-click a variable and enter a new value (which is just like entering an assignment statement in the Immediate window). Also note that variables with multiple dimensions (such as arrays or objects) are displayed in a tree-like hierarchy. This feature can be handy when you are dealing with complex objects such as an ADO recordset. |
|
|
|
|
|